unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,ComObj, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Memo1: TMemo;
    IdHTTP1: TIdHTTP;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
    function requestData(AFunction : String;AParmList : TStrings;sURL : String=''):String;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  voXmlhttp : Variant;
  sText : string;
  List : TStrings;
begin
  List := TStringList.Create;
  try
    List.Values['sql'] := 'select * from as_user where user_id=''sa'' ';
    List.Values['token'] := '2015';
    sText := requestData('fQuery',List);
  finally
    List.Free;
  end;

  Memo1.Lines.Add(sText);

end;

procedure TForm1.Button2Click(Sender: TObject);
var
  voXmlhttp : Variant;
  sText : string;
  List : TStrings;
begin
  List := TStringList.Create;
  try
    List.Values['sql'] := 'update as_user set USER_NAME= ''test'' where user_id=''123'' ';
    List.Values['token'] := '2015';
    sText := requestData('fExecute',List);
  finally
    List.Free;
  end;

  Memo1.Lines.Add(sText);
end;

//!@#$
procedure TForm1.Button3Click(Sender: TObject);
var
  voXmlhttp : Variant;
  sText : string;
  List : TStrings;
begin
  List := TStringList.Create;
  try
    List.Values['sql'] := 'update as_user set USER_NAME= ''test'' where user_id=''123'' ';
    List.Values['token'] := '2015';
    sText := requestData('fBatchExecute',List);
  finally
    List.Free;
  end;

  Memo1.Lines.Add(sText);

end;

function TForm1.requestData(AFunction : String;AParmList : TStrings;sURL : String=''): String;
var
  PList : TStrings;
  i : Integer;
  sKey,sVal : string;
  voXmlhttp : Variant;
  sText : string;
const
  BASE_URL = 'http://192.168.19.130:8002/GL/';
begin
	if sURL ='' then
    sURL := BASE_URL + '/XmlProxy';
  PList := TStringList.Create;
  try
    PList.Add('<?xml version="1.0"?>');
    PList.Add('<root>');
    PList.Add('<function>'+AFunction+'</function>');
    PList.Add('<componame>All</componame>');
    for i := 0 to AParmList.Count - 1 do
    begin
      sKey := AParmList.Names[i];
      sVal := AParmList.Values[sKey];
      PList.Add('<'+sKey+'><![CDATA['+ sVal+ ']]></'+sKey+'>');
    end;
    PList.Add('</root>');

    voXmlhttp := CreateOleObject('Microsoft.XMLHTTP');
    voXmlhttp.Open('POST', sURL, False);
  	voXmlhttp.setRequestHeader('Content-Length', Length(PList.Text));
  	voXmlhttp.setRequestHeader('Content-Type','text/xml');
    voXmlhttp.send(PList.Text);
    Result := voXmlhttp.responseText;
  finally
    PList.Free;
  end;

end;



procedure TForm1.Button4Click(Sender: TObject);
var
  voXmlhttp : Variant;
  sText : string;
  List : TStrings;
begin
  List := TStringList.Create;
  try
    List.Values['func'] := 'Query';
    List.Values['sql'] := 'select * from as_user where user_id=''sa'' ';
    List.Values['token'] := 'supersa@!';
    sText := requestData('fDoSql',List);
  finally
    List.Free;
  end;

  Memo1.Lines.Add(sText);

end;

end.
